﻿using System;
using System.Data;
using System.Collections.Generic;
using LTP.Common;
using Maticsoft.Model;
namespace Maticsoft.BLL
{

    /// <summary>
    /// bll 的摘要说明
    /// </summary>
    public class bll_api_delay
    {
        private readonly Maticsoft.DAL.dao_api_delay dal = new Maticsoft.DAL.dao_api_delay();

        public bll_api_delay()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }

        #region  Method

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return dal.GetMaxId();
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int id)
        {
            return dal.Exists(id);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(Maticsoft.Model.model_api_delay model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Maticsoft.Model.model_api_delay model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int id)
        {

            return dal.Delete(id);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string idlist)
        {
            return dal.DeleteList(idlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Maticsoft.Model.model_api_delay GetModel(int id)
        {

            return dal.GetModel(id);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Maticsoft.Model.model_api_delay GetModelByAppCode(string appcode)
        {

            return dal.GetModelByAppCode(appcode);
        }


        /// <summary>
        /// 得到一个对象实体，从缓存中
        /// </summary>
        public Maticsoft.Model.model_api_delay GetModelByCache(int id)
        {

            string CacheKey = "newscontentModel-" + id;
            object objModel = LTP.Common.DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(id);
                    if (objModel != null)
                    {
                        int ModelCache = LTP.Common.ConfigHelper.GetConfigInt("ModelCache");
                        LTP.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (Maticsoft.Model.model_api_delay)objModel;
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中
        /// </summary>
        public Maticsoft.Model.model_api_delay GetModelByCacheWithAppCode(string appcode)
        {

            string CacheKey = "newscontentModelByAppCode-" + appcode;
            object objModel = LTP.Common.DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModelByAppCode(appcode);
                    if (objModel != null)
                    {
                        int ModelCache = LTP.Common.ConfigHelper.GetConfigInt("ModelCache");
                        LTP.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (Maticsoft.Model.model_api_delay)objModel;
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Maticsoft.Model.model_api_delay> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Maticsoft.Model.model_api_delay> DataTableToList(DataTable dt)
        {
            List<Maticsoft.Model.model_api_delay> modelList = new List<Maticsoft.Model.model_api_delay>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {   
                Maticsoft.Model.model_api_delay model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Maticsoft.Model.model_api_delay();

                    if (dt.Rows[n]["id"] != null && dt.Rows[n]["id"].ToString() != "")
                    {
                        model.id = int.Parse(dt.Rows[n]["id"].ToString());
                    }
                    if (dt.Rows[n]["apiname"] != null && dt.Rows[n]["apiname"].ToString() != "")
                    {
                        model.apiname = dt.Rows[n]["apiname"].ToString();
                    }
                    if (dt.Rows[n]["apiurl"] != null && dt.Rows[n]["apiurl"].ToString() != "")
                    {
                        model.apiurl = dt.Rows[n]["apiurl"].ToString();
                    }
                    if (dt.Rows[n]["apimemo"] != null && dt.Rows[n]["apimemo"].ToString() != "")
                    {
                        model.apimemo = dt.Rows[n]["apimemo"].ToString();
                    }
                    if (dt.Rows[n]["status"] != null && dt.Rows[n]["status"].ToString() != "")
                    {
                        model.content = dt.Rows[n]["status"].ToString();
                    }
                    if (dt.Rows[n]["contenttype"] != null && dt.Rows[n]["contenttype"].ToString() != "")
                    {
                        model.contenttype = dt.Rows[n]["contenttype"].ToString();
                    }
                    if (dt.Rows[n]["content"] != null && dt.Rows[n]["content"].ToString() != "")
                    {
                        model.content = dt.Rows[n]["content"].ToString();
                    }
                    if (dt.Rows[n]["isusing"] != null && dt.Rows[n]["isusing"].ToString() != "")
                    {
                        model.isusing = bool.Parse(dt.Rows[n]["isusing"].ToString());
                    }
                    if (dt.Rows[n]["httpmethod"] != null && dt.Rows[n]["httpmethod"].ToString() != "")
                    {
                        model.httpmethod = dt.Rows[n]["httpmethod"].ToString();
                    }
                    if (dt.Rows[n]["appcode"] != null && dt.Rows[n]["appcode"].ToString() != "")
                    {
                        model.appcode = dt.Rows[n]["appcode"].ToString();
                    }
                    if (dt.Rows[n]["appqueue"] != null && dt.Rows[n]["appqueue"].ToString() != "")
                    {
                        model.appqueue = dt.Rows[n]["appqueue"].ToString();
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            return dal.GetRecordCount(strWhere);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }

        #endregion  Method



    }
}